t = int(input())
d = 0
if len(str(t)) == 4:
    for i in range(2, t // 2 + 1):
        if z % i == 0:
            break
    else:
        d = t
    n = str(t)
    for i in range(len(n)):
        for j in range(i+1, len(n)+1):
            if i == 0 and n[i] == '0':
                continue
            x = int(n[i:j])
            for k in range(2, x):
                if x % k == 0:
                    break
            else:
                if x > d:
                    d = x

print(d)
